import Base from "../Base.js";
import usersApi from "../../api/users.js";
export default class extends Base {
    constructor(props) {
        super(props);
        this.user = sessionStorage.getItem("user");
        this.user = JSON.parse(this.user);
    }
    handle() {
        $("input").on("input", e => {
            this.user[e.target.name] = e.target.value;
        })
        $("#updata").on("click", async e => {
            const data = await usersApi.updata(this.user);
            console.log(data);
            data.ok ? location.hash = "#/info/usersList" : layui.layer.msg("更新失败");
        })
    }
    render() {
        this.el.html(`
            <h1 style="margin: 0 0 20px 110px;">更新用户</h1>
            <form class="layui-form" action="">
                <div class="layui-form-item">
                    <label class="layui-form-label">账号</label>
                    <div class="layui-input-block">
                        <input type="text" name="userName" required lay-verify="required" autocomplete="off"
                        class="layui-input" style="width: 200px;" value='${this.user.userName}'>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">密码</label>
                    <div class="layui-input-block">
                        <input type="text" name="userPassword" required lay-verify="required" autocomplete="off"
                        class="layui-input" style="width: 200px;" value='${this.user.userPassword}'>
                    </div>
                </div>
                <div class="layui-form-item">
                <div class="layui-input-block">
                    <input type="button" value="更新" class="layui-btn" id="updata">
                    <input type="reset" value="重置" class="layui-btn">
                </div>
            </div>
            </form>
        `);
        layui.form.render();
    };
}
